package schach.server.model;

import java.io.Serializable;
import java.util.ArrayList;

public class Bauer extends Figur{

	public Bauer(Feld position, boolean alive, boolean black) {
		super(position, alive, black);
	}

	@Override
	public ArrayList<Feld> crossedFields(Feld f, boolean schlagen) throws NullPointerException {
		ArrayList<Feld> results = new ArrayList<Feld>();
		int deltaX = f.getX() - getPosition().getX();
		int deltaY = f.getY() - getPosition().getY();
		if(this.isBlack() && deltaY < 0 && deltaY > -3 && deltaX == 0 && !schlagen){
			if(deltaY == -1)
				results = null;
			else if(deltaY == -2 && getNoOfMoves() == 0){
				results.add(new Feld(f.getX(), f.getY() + 1));
			}
			else
				throw new NullPointerException();
		}
		else if(!this.isBlack() && deltaY > 0 && deltaY < 3 && deltaX == 0 && !schlagen){
			if(deltaY == 1)
				results = null;
			else if(deltaY == 2 && getNoOfMoves() == 0){
				results.add(new Feld(f.getX(), f.getY() - 1));
			}
			else
				throw new NullPointerException();
		}
		else if(this.isBlack() && deltaY == -1 && Math.abs(deltaX) == 1 && schlagen)
			results = null;
		else if(!this.isBlack() && deltaY == 1 && Math.abs(deltaX) == 1 && schlagen)
			results = null;
		else{
			throw new NullPointerException();
		}
		return results;
	}
}
